package com.settlement.system.service.impl;

import com.settlement.system.mapper.BaseMapper;
import com.settlement.system.mapper.TblAcsUserMapper;
import com.settlement.system.mapper.TblAcsUserRoleAuthorityMapper;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblAcsUser;
import com.settlement.system.service.ITblAcsUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;

/**
 * ACS用户 服务实现类
 * @author xiaochuan
 * @since 2020-06-02
 */
@Service
public class TblAcsUserServiceImpl extends BaseServiceImpl implements ITblAcsUserService {

    @Resource
    private TblAcsUserMapper tblAcsUserMapper;

    @Resource
    private TblAcsUserRoleAuthorityMapper tblAcsUserRoleAuthorityMapper;

    @Override
    public BaseMapper init() {
        return tblAcsUserMapper;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = ServiceException.class)
    public void deleteUser(TblAcsUser model) throws ServiceException {
        try {
            //删除主表
            tblAcsUserMapper.deleteById(model);
            //删除明细表
            tblAcsUserRoleAuthorityMapper.deleteByLoginName(model.getLoginName());
        } catch (Exception ex){
            throw new ServiceException("删除数据异常",ex);
        }
    }

}

